package servlet.zhouchao;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import pojo.Goods;
import service.GoodsService;
import service.impl.GoodsServiceImpl;
import util.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(value = "/GoodsPageBeanListServlet")
public class GoodsPageBeanListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=UTF-8");
        GoodsService goodsService=new GoodsServiceImpl();
        PageBean pb=new PageBean();
        String pageIndex=request.getParameter("pageIndex");
        if(null==pageIndex){
            pb.setPageIndex(1);
        }
        else{
            pb.setPageIndex(Integer.parseInt(pageIndex));
        }
        pb.setPageSize(10);
        String name=request.getParameter("goName");
        if(null!=name){
            name=new String(name.getBytes("ISO-8859-1"),"UTF-8");
        }
        request.setAttribute("goName",name);
        pb=goodsService.queryAllGoodsInfo(pb,name);
        request.setAttribute("pb",pb);

        request.getRequestDispatcher("jsp/zc/GoodsList.jsp").forward(request,response);


    }
}
